package com.richinfo.config;

import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class Config {
	
	private static Logger logger = Logger.getLogger(Config.class);
	private static Properties properties = new Properties();
	
	public static void init()
	{
		String log4jFilePath = "D:\\log4j.properties";
		PropertyConfigurator.configure(log4jFilePath);
		logger.info("Loaded log4j.properties");
		
		String proxoolPath = "proxool.properties";
		
		String configFilePath = "D:\\config.properties";
		try {
			FileInputStream fis = new FileInputStream(configFilePath);
			properties.load(fis);
			logger.info("Loaded config.properties");
		} catch(FileNotFoundException ee) {
			System.out.println(ee.getMessage());
		} catch(IOException ee) {
			System.out.println(ee.getMessage());
		}
	}
	
	public String getProperty(String key) {
		if(properties == null) {
			logger.info("System is not inited, Constants' sysCfgProp is null");
			return null;
		}
		
		String temp = properties.getProperty(key);
		return temp.trim();
	}
	
	public String getProperty(String key, String defaultSTR) {
		if(properties == null) {
			logger.info("System is not inited, Constants' sysCfgProp is null");
			return null;
		}
		
		String temp = properties.getProperty(key);
		if(temp != null) {
			return temp.trim();
		}
		else {
			return defaultSTR;
		}
	}
}
